<template>
  <div class="common-table">
    <el-table :data="tableData" height="90%" stripe>
      <el-table-column
        show-overflow-tooltip
        v-for="item in tableLabel"
        :key="item.prop"
        :label="item.label"
        :width="item.width ? item.width : 125"
      >
        <template #default="scope">
          <span style="margin-left: 10px">{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="180">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-popconfirm
            confirm-button-text="确定"
            cancel-button-text="取消"
            icon-color="red"
            title="你确定要删除吗？"
            @confirm="handleDelete(scope.row)"
          >
            <template #reference>
              <el-button size="small" type="danger">删除</el-button>
            </template>
          </el-popconfirm>
          
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pager"
      layout="prev, pager, next"
      :total="config.total"
      :page-size="10"
      v-model:current-page="config.page"
      @current-change="changePage"
    ></el-pagination>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue';

defineProps({
  tableData: Array,
  tableLabel: Array,
  config: Object
});

const emit = defineEmits<{
  (e: 'edit', row: Object): void,
  (e: 'delete', row: Object): void,
  (e: 'changePage', page: number): void
}>();

const handleEdit = (row: Object) => {
  emit('edit', row);
}
const handleDelete = (row: Object) => {
  emit('delete', row);
}
const changePage = (page: number) => {
  emit('changePage', page);
}
</script>

<style lang="less" scoped>
.common-table {
  height: calc(100% - 62px);
  background-color: white;
  position: relative;
  .pager {
    position: absolute;
    bottom: 0;
    right: 20px;
  }
}
</style>
